package com.sunyy.codegenerator.config;

import com.mybatisflex.core.audit.AuditManager;
import lombok.extern.slf4j.Slf4j;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.context.annotation.Configuration;

/**
 * @author sunyy
 * @since 2025/7/19
 */
@Slf4j
@Configuration
@MapperScan("com.sunyy.codegenerator.mapper")
public class MybatisFlexConfig {

    public MybatisFlexConfig() {
        //开启审计功能
        AuditManager.setAuditEnable(true);

        //设置 SQL 审计收集器
        AuditManager.setMessageCollector(auditMessage ->
                log.info("{},\n耗时{}ms", auditMessage.getFullSql()
                        , auditMessage.getElapsedTime())
        );
    }
}
